package com.dzu.medium;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ZhaoDong
 * @date 2022/10/14 10:06
 * @description 535. TinyURL 的加密与解密
 */
public class Test535 {

    public static void main(String[] args) {

    }
}


class Codec {
    private Map<Integer, String> dataBase = new HashMap<>();
    private int id;

    public String encode(String longUrl) {
        id++;
        dataBase.put(id, longUrl);
        return "http://tinyurl.com/" + id;
    }

    public String decode(String shortUrl) {
        int p = shortUrl.lastIndexOf('/') + 1;
        int key = Integer.parseInt(shortUrl.substring(p));
        return dataBase.get(key);
    }
}

